#ifndef CONTROL_H
#define CONTROL_H

#include <QWidget>
#include <QTime>
#include <QButtonGroup>
#include <QtCharts/QChartView>
#include <QSplineSeries>
#include <QTextCharFormat>
#include <QValueAxis>

namespace Ui {
class control;
}

using namespace QtCharts;

class control : public QWidget
{
    Q_OBJECT

public:
    explicit control(QWidget *parent = nullptr);
    ~control();

private slots:
    void on_Bt_CtrlBack_clicked();

    void on_Bt_Ctrl0_clicked();

    void on_Bt_CtrlStraight_clicked();
protected:
    void keyPressEvent(QKeyEvent *event);   //键盘按下事件
private:
    Ui::control *ui;

    /* 下面为自定义方法和属性 */
private:
    QButtonGroup *pbuttonGroup;
    uint8_t MotorDataNum;
    void CreateChart(void);
    int WaveFormMax;

public:
    QChart* chart_angle;
    QChart* chart_speed;
    QChart* chart_current;

    QValueAxis *Angleaxis_y;
    QValueAxis *Speedaxis_y;
    QValueAxis *Iqaxis_y;

    QLineSeries *lsAngle;
    QLineSeries *lsSetAngle;
    QLineSeries *lsSpeed;
    QLineSeries *lsSetSpeed;
    QLineSeries *lsIq;
    QLineSeries *lsSetIq;

    float setAngle;
    float setSpeed;
    float setIq;

    uint8_t GetCtrlData(float &_txData);
    void showAngleAdd(double data);
    void showSpeedAdd(double data);
    void showIqdAdd(double data);
    void set_wh(int w, int h);
private:
    void showObjAdd(QChart *ChaObj, QLineSeries *LinObj, double data, QValueAxis *qva, uint64_t &x, double max, double min);
    void showObjAdd(QChart *ChaObj, QLineSeries *LinObj, double data, QValueAxis *qva, uint64_t &x);

private slots:
    void onRadioClickSlot();
    void TxData(uint8_t Motor, float data);
    void on_Slider_3_sliderMoved(int position);
    void on_Slider_3_sliderPressed();
    void on_Bt_ClearAll_clicked();
    void on_Bt_setWaveFormMax_clicked();

public:
    void CtrDebug(QString color, QString text);
    void CtrDebug(QString color1, QString text1, QString color2, QString text2);

protected:
    bool eventFilter(QObject *obj, QEvent *e);
};

extern control *c;

#endif // CONTROL_H
